package online.test1;

import java.util.StringJoiner;

/**
 * @Author 28021
 * @Date 2022/10/10
 */
public class StringJoinerTest {
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        String str = arrToString1(arr);
        System.out.println(str);
    }
    public static String arrToString1(int[] arr ){
//        StringBuilder sb = new StringBuilder();
//        sb.append("[");
        StringJoiner sj = new StringJoiner(",","[","]");

        for (int i = 0; i < arr.length; i++) {
//            if(i == arr.length -1){
//                sb.append(arr[i]);
            sj.add(arr[i]+"");
//            }else{
//                sb.append(arr[i]).append(",");
//            }
        }
//        sb.append("]");
//        return  sb.toString();//sb为容器，变为字符串
        return sj.toString();

    }
}
